package sz.szsmk.citizencard.ui.dzsmkavtivity;

import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.model.network.dzbean.res.Bank;
import sz.szsmk.citizencard.mvp.BankListMvpView;
import sz.szsmk.citizencard.mvp.BasePresenter;
import sz.szsmk.citizencard.mvp.dzsmkpresenter.BankPresenter;

import java.util.ArrayList;

import javax.inject.Inject;

/**
 * Created by yangzhengwen on 2017/10/1.
 */

public class SupportBankListActivity extends AppBaseActivity implements BankListMvpView {

    RecyclerView rv_qr_list;

    @Inject
    BankPresenter bankPresenter;
    private Bank bank;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getComponent().inject(this);
        setContentView(R.layout.qr_activity_recyclerview);
        rv_qr_list = findViewById(R.id.rv_qr_list);
        bankPresenter.getSupportBankList();
    }

    @Override
    protected BasePresenter[] initPresenters() {
        return new BasePresenter[]{bankPresenter};
    }

    @Override
    protected CharSequence getTopTitle() {
        return getString(R.string.qr_bank_list);
    }

    @Override
    public void onGetBanksFail() {

    }

    @Override
    public void onGetBanksInfo(ArrayList<Bank> list) {

        rv_qr_list.setLayoutManager(new LinearLayoutManager(SupportBankListActivity.this));
        BaseQuickAdapter bankAdapter = new BaseQuickAdapter<Bank, BaseViewHolder>(R.layout.qr_item_support_bank, list) {

            @Override
            protected void convert(BaseViewHolder helper, Bank item) {
                helper.setText(R.id.tv_qr_bank_name, item.getBankName());
                ImageView imageView = helper.getView(R.id.iv_qr_bank_icon);
                Glide.with(SupportBankListActivity.this).load(item.getBankIconUrl()).placeholder(R.drawable.qr_ic_banklog).error(R.drawable.qr_ic_banklog).into(imageView);
            }
        };
        bankAdapter.openLoadAnimation();
        rv_qr_list.setAdapter(bankAdapter);
    }
}
